﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;

using KPIS.GERP.GFMS.APP.App_UI.Commons;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.MODEL;

namespace KPIS.GERP.GFMS.APP.App_UI.Forms
{
    public partial class ESS_ProjectHistory_old : System.Web.UI.Page
    {
        Main main = new Main();
        IBLL_BGM_ProjectOperation pj = new B_BGM_ProjectOperation();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int year = main.GetSystemControls().default_bgm_year.Value;
                txtBgmYear.Text = year.ToString();
                txtBgmYear.MinValue = year - 10;
                txtBgmYear.MaxValue = year + 1;
                //grdBgmProjectHistory.MasterTableView.FilterExpression = "([m_bgm_project.bgm_proj_name] LIKE {0})";

                //GridColumn column = grdBgmProjectHistory.MasterTableView.GetColumnSafe("m_bgm_project.bgm_proj_name");
                //column.CurrentFilterFunction = GridKnownFunction.Contains;
                //column.CurrentFilterValue = "Germany";
                //LoadGrdBgmProjectHistory();
            }
        }

        public void LoadGrdBgmProjectHistory()
        {
            grdBgmProjectHistory.DataSource = pj.GetFull(null, txtBgmYear.Text, Session["UserInternalJobsiteSeq"].ToString()
                , null, null, false, false);
        }

        protected void grdBgmProjectHistory_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                LoadGrdBgmProjectHistory();
            }
        }

        //protected void grdBgmProjectHistory_ItemCommand(object source, GridCommandEventArgs e)
        //{
        //    if (e.CommandName == "DataEdit")
        //    {
        //        string strBgmProjectSeq =  main.WebString(grdBgmProjectHistory.Items[e.Item.ItemIndex]["bgm_proj_oper_seq"].Text);
        //        Session["EditSeq"] = strBgmProjectSeq;
        //        //((Label)Parent.FindControl("lblMode")).Text = "Edit";
        //        //((Label)Parent.FindControl("lblBgmProjectSeq")).Text = strBgmProjectSeq;

        //        string strClosePopupScript = "<script> returnToParent(); </script>";
                
        //        Page.ClientScript.RegisterStartupScript(Page.GetType(), "ClosePopupScript", strClosePopupScript);
        //    }
        //}

        protected void cmdSearch_Click(object sender, ImageClickEventArgs e)
        {
            //LoadGrdBgmProjectHistory();
            
            //grdBgmProjectHistory.DataBind();
            //GridColumn column = grdBgmProjectHistory.MasterTableView.GetColumnSafe("Country");
            //column.CurrentFilterValue = txtBgmRecName.Text;
            //grdBgmProjectHistory.Rebind();
        }

        protected void grdBgmProjectHistory_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                ((ImageButton)e.Item.FindControl("cmdDelete")).Visible
                //((ImageButton)grdBgmProjectHistory.Items[e.Item.ItemIndex]["delete"].FindControl("cmdDelete")).Visible
                    = ((M_BGM_ProjectOperation)e.Item.DataItem).record_status != "A";
            }
        }
    }
}
